package com.yafeng.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2  //开启swagger2
public class MySwaggerConfig {


    @Bean
    public Docket docket_one(){

        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("one")
                .select()
                .paths(Predicates.not(PathSelectors.regex("/admin/.*")))
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                //.paths(PathSelectors.ant(""))  //过滤
                //.apis(RequestHandlerSelectors.withMethodAnnotation(RestController.class))
                .build();

    }
    @Bean
    public Docket docket_two(){

        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("two")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yafeng"))
                //.paths(PathSelectors.ant(""))  //过滤
                //.apis(RequestHandlerSelectors.withMethodAnnotation(RestController.class))
                .build();

    }
    private ApiInfo apiInfo() {


        //String title, String description, String version, String termsOfServiceUrl, String contactName, String license, String licenseUrl
        return new ApiInfo(

                "byp的swagger文档",
                "this is a demo",
                "v1.0",
                "http://classBao.cn",
                new Contact("baoyanpei","http://classBao.cn","591501878@163.com"),
                "no license",
                "no licenseUrl",
                new ArrayList()

        );

    }

}